<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
    <p>父标签传递参数及方法给子标签</p>
    <counter :num1="num" @incr1="incr()"></counter>
</div>
</body>
<script src="node_modules/vue/dist/vue.js"></script>
<script>
    //全局组件，即子标签
    Vue.component("counter", {
        //模型，即组件的内容
        template: "<button @click='submit1'>点我即可加一，{{num1}}</button>",
        // props: ["num1"]
        //props验证
        props: {
            //指定传入值
            num1: {
                //类型
                type: Number,
                //默认值
                default: 0
            }
        },
        methods: {
            //在执行子组件的方法时调用父组件的方法
            submit1() {
                this.$emit("incr1");
            }
        }
    })

    const app = new Vue({
        el: "#app",
        data: {
            num: 0
        },
        methods: {
            incr() {
                this.num++;
            }
        }
    })
</script>
</html>